<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			input {
				margin: 6px 10px 6px;
				padding: 2px 12px;
			}
			#in1 {
				width: 1500px;
				line-height: 22px;
			}
		</style>
		
		<script type="text/javascript">
			// console.log(document.getElementById("userName").value);
			// console.log(document.getElementsByName("username")[0].value);
			// console.log(document.forms[0].userName.value);
			// console.log(document.form1.userName.value);
		</script>
		<script>
			/* var obj = ();
			var obj1 = [];
			var obj2 = {};
			var obj3 = //;
			cosole.log(obj);
			cosole.log(obj1);
			cosole.log(obj2);
			cosole.log(obj3); */
			
			/* 全局变量测试 */
			var golableVar = 555;
			function a () {
				var localVar = 666;
				alert(golableVar);
			}
			
			function b () {
				alert(golableVar);
			}
			
			gv = 777;
			function c() {
				alert(gv);
			}
			
			function d() {
				gv1 = 888;
			}
			
			function d1() {
				alert(gv1);/* 执行d()后，gv1变成全局变量 */
			}
		</script>
		<script>
			console.log(window.innerHeight);//输出：1920	-- 1920
			console.log(window.innerWidth);//输出：937	-- 1080
			
			var height = window.innerHeight || document.documentElement.cilentHeight || document.body.clientHeight;
			console.log("窗口高为：" + height);
			var width = window.innerWidth || document.documentElement.cilentWidth || document.body.clientWidth;
			console.log("窗口宽为：" + width);
		</script>
		<script>
			function closeThisWindow() {
				window.close();
			}
			function openThisWindow() {
				// window.open();
				window.open(window.location, "_blank");
			}
		</script>
		<script>
			function getThisWindowUrl() {
				var input = document.getElementById("in1");
				input.value = window.location;
				var table = document.createElement();
				document.write("主机名：" + window.location.hostname + "<br />");
				document.write("路径名：" + window.location.pathname + "<br />");
				document.write("协议名：" + window.location.protocol + "<br />");
				console.log("端口：" + location.port);
			}
		</script>
	</head>
	<body>
		<form id="form1">
		    <input type="text" id="userName" name="userName value="123" />
			
		</form>
		<br />
		
		<a href="www.bai.com">百度</a><br /><hr />
		
		<h4>全局变量声明方式一：使用var关键字声明在方法外</h4>
		<input type="button" onclick="a()" value="全局变量测试1" /><br />
		<input type="button" onclick="b()" value="全局变量测试2" /><br /><hr />
		<h4>全局变量声明方式一：</h4>
		<input type="button" onclick="c()" value="全局变量测试3" /><br /><hr />
		<input type="button" onclick="d()" value="全局变量测试4" />
		<input type="button" onclick="d1()" value="全局变量测试5" /><br /><hr />
		<h4>关闭窗口测试</h4>
		<input type="button" value="关闭窗口" onclick="closeThisWindow()" /><br /><hr />
		<h4>打开新窗口测试</h4>
		<input type="button" value="打开窗口" onclick="openThisWindow()" /><br /><hr /> 
		<h4>获取当前页面的地址</h4>
		<input type="button" value="获取window对象" onclick="getThisWindowUrl()" />
		<input id="in1" readonly type="text" /><br /><hr />
	</body>
</html>
